package Final;

import java.util.Scanner;

public class test10 {
    public static void main(String[] args) {
        Matrix firstMat = Matrix.inputMatrix();
        display(firstMat.matrix);
        Matrix secondMat = Matrix.inputMatrix();
        display(secondMat.matrix);
        Matrix productMat = firstMat.multiply(secondMat);
        display(productMat.matrix);
    }

    //display方法：打印二维数组元素到屏幕
    public static void display(int[][] array) {
        for (int i = 0; i < array.length; i++) {
            for (int j = 0; j < array[i].length; j++) {
                if (j == array[i].length - 1) {
                    System.out.println(array[i][j]);
                } else {
                    System.out.print(array[i][j] + " ");
                }
            }
        }
    }
}

/* 请在这里填写答案 */
class Matrix {
    static Scanner sc = new Scanner(System.in);
    int[][] matrix;

    public Matrix(int rows,int cos) {
        this.matrix = new int[rows][cos];
    }

    public Matrix(int[][] matrix) {
        this.matrix = matrix;
    }

    public static Matrix inputMatrix() {

        int x = sc.nextInt();
        int y = sc.nextInt();
        int [][]m = new int[x][y];
        for (int i = 0; i < x; i++) {
            for (int j = 0; j < y; j++) {
                m[i][j] = sc.nextInt();
            }
        }
        return new Matrix(m);
    }

    public int[][] getMatrix() {
        return matrix;
    }
    public Matrix multiply(Matrix secondMat) {
        int rows = matrix.length;
        int count = matrix[0].length;
        int cons = secondMat.matrix[0].length;
        Matrix m = new Matrix(rows,cons);
        int [][]result = m.matrix;
        for (int i = 0; i < rows; i++) {
            for (int j = 0; j < cons; j++) {
                for (int k = 0; k < count; k++) {
                    result[i][j] += matrix[i][k] * secondMat.matrix[k][j];
                }
            }
        }
        return m;
    }
}